package parser;

import lexer.Token;

/**
 * Returns the precedence of an operator from it's Token. This keeps all
 * precedence code out of the Lexer package, which is where it would have to be
 * to store the precendence in the Token class
 */
public class LogoPrecedence {
	public static int getPrecendence(Token token) {
		// This logic is here to reduce the code in the BinaryExpression file
		if (token == null) {
			return 0;
		}

		switch (token.getType()) {
		case MULTIPLY:
		case DIVIDE:
			return 4;

		case ADD:
		case SUBTRACT:
			return 3;

		case GREATER_THAN:
		case LESS_THAN:
		case GREATER_THAN_OR_EQUAL:
		case LESS_THAN_OR_EQUAL:
			return 2;

		case EQUALS:
		case NOT_EQUALS:
			return 1;

		default:
			return 0;
		}
	}
}
